﻿using FanaticRock.Core.DI;
using FanaticRock.Core.ServiceInterfaces;
using System.IO;

namespace FanaticRock.Services
{
    // 音频的本地存储。
    [InjectMe(typeof(ILocalStorageService))]
    public class BilibiliVideoLocalStorageService : ILocalStorageService
    {
        private string _rootDir;
        private const string BvidName = "bvid";
        private const string AvidName = "avid";
        private const string AudioName = "audio.mp4";

        public BilibiliVideoLocalStorageService()
        {
#if DEBUG
            _rootDir = @"F:\afanatic";
#else
            var baseDir = AppDomain.CurrentDomain.BaseDirectory;
            var parentDir = Path.GetDirectoryName(baseDir);
            var storageDir = Path.Combine(parentDir, "fanaticrockstorage");
            _rootDir = storageDir;
#endif

        }

        public BilibiliVideoLocalStorageService(string rootDir)
        {
            _rootDir = rootDir;
        }

        ///<summary>文件保存。</summary>
        public string GetBvidAudioPath(string bvid)
        {
            return Path.Combine(_rootDir, BvidName, bvid, AudioName);
        }

        public string GetAvidAudioPath(long avid)
        {
            return Path.Combine(_rootDir, AvidName, avid.ToString(), AudioName);
        }

        public string GetPath(string key)
        {
            return Path.Combine(_rootDir, BvidName, key, AudioName);
        }

    }
}
